<template>
  <div class="usercenter-page">
    <div class="usercenter-contain">
      <div class="home-head-user">
        <div class="home-head-user-icon">
          <img v-lazy="userInfo.head_img_url">
        </div>
        <div class="home-des">
          <div class="home-des-detail">
            <span class="home-name">{{userInfo.nick_name}}</span>
          </div>
        </div>
      </div>
      <div class="home-list">
        <div class="home-item" @click.stop.prevent='jumpAccount'>
          账号与安全
        </div>
        <div class="home-item" @click.stop.prevent='jumpMyOrder'>
          我的订单
        </div>
        <div class="home-item" @click.stop.prevent='jumpAddress'>
          我的地址
        </div>
      </div>
    </div>
    <footer-tab :iscur="tabView"></footer-tab>
  </div>
</template>

<script>
import Vue from 'vue'
import { Lazyload } from 'vant'
import {CODE, APIURI} from '#/common/js/apiConst'
import FooterTab from '#/footer/footer'

Vue.use(Lazyload)
export default {
  data() {
    return {
      tabView: 'user',
      userInfo: {}
    }
  },
  created() {
    this.getUserInfo()
  },
  components: {
    FooterTab
  },
  methods: {
    jumpAccount() {
      this.$router.push({ path: '/user/account' })
    },
    jumpMyOrder() {
      this.$router.push({ path: '/user/orderlist' })
    },
    jumpAddress() {
      this.$router.push({ path: '/user/addresslist?source=usercenter' })
    },
    getUserInfo() {
      this.$axios
        .get(APIURI + '/member')
        .then(res => {
          res = res.data
          if (res.code === CODE) {
            this.userInfo = res.data
          } else if (res.code === -2) {
            this.$router.push({ path: '/login' })
          }
        })
        .catch(function(err) {
          console.log(err)
        })
    }
  }
}
</script>

<style lang="scss" scoped>
@import './../common/scss/common.scss';
.usercenter-page {
  .usercenter-contain {
    .home-head-user {
      @include leftFlexCenter();
      width: 100%;
      height: 90px;
      overflow: hidden;
      background-color: $white;
      .home-head-user-icon {
        margin-left: 15px;
        img {
          width: 74px;
          height: 74px;
          border-radius: 50%;
        }
      }
      .home-des {
        .home-name {
          margin-left: 14px;
          font-size: 16px;
          color: #474245;
        }
      }
    }
    .home-list {
      width: 100%;
      margin-top: 20px;
      background-color: $white;
      .home-item {
        position: relative;
        line-height: 60px;
        width: 90%;
        display: block;
        color: #262626;
        font-size: 15px;
        background: #fff;
        margin-left: 16px;
        border-top: 1px solid #f0f0f0;
        &:after {
          content: '';
          width: 17px;
          height: 17px;
          background: url(https://static-as.missfresh.cn/frontend/img/right-jiantou.png)
            no-repeat;
          background-size: 100% 100%;
          position: absolute;
          right: 0;
          top: 21px;
        }
      }
    }
  }
}
</style>